<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
        <com-a></com-a>
    </div>
    <template id="coma">
        <div>
            <h1>我是coma组件{{myname}}</h1>
            <com-b></com-b>
        </div>

    </template>
    <template id="comb">
        <div>
            <h1>我是comb组件{{myname}}</h1>
        </div>

    </template>
    <script>
        // provide 和 inject 跨层级 。不推荐直接使用
        // 迪米特法则 ，最少知识原则 。不要和陌生人讲话
        let ComB = {
            inject:["myname"],
            template:"#comb"
        }


        let ComA = {
            inject:["myname"],
            template:"#coma",
            components:{
                ComB 
            }
        }



        new Vue({
            el:"#app",
            provide:function(){
                return {
                    myname:"张三"
                }
            },
            components:{
                ComA 
            }
        })


    </script>
</body>
</html>